const axios = require('axios')

const defaultConfig = {
	baseURL: '',
	timeout: 6000,
	headers: { 'X-Custom-Header': 'foobar' }
}

const instance = axios.create({
	...defaultConfig
})

module.exports = ({ method, url, data = {} }, config = {}) => {
	method = (method || '').toLowerCase()
	return instance({
		...config,
		url,
		method: method || 'post',
		[method === 'get' ? 'params' : 'data']: data
	})
}
